/**
 * 系统管理--用户管理的单例对象
 */
var sharesArePeople = {
    id: "sharesArePeopleTable",//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    deptid:0
};

/**
 * 初始化表格的列
 */
sharesArePeople.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '姓名', field: 'peopleName', align: 'center', valign: 'middle', sortable: true, width: 100},
        {title: '性别', field: 'sex', align: 'center', valign: 'middle', sortable: true, width: 100},
        {title: '年龄', field: 'age', align: 'center', valign: 'middle', sortable: true, width: 80},
        {title: '电话', field: 'phone', align: 'center', valign: 'middle', sortable: true, width: 110},
        {title: '邮箱', field: 'email', align: 'center', valign: 'middle', sortable: true, width: 110},
        {title: '创建时间', field: 'createtime', align: 'center', valign: 'middle', sortable: true, width: 170},
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true, width: 100,
            formatter: function (value, row, index) {
                return "<span title='"+value+"'>" + value + "</span>"
            },
            cellStyle: function (value, row, index) {
                return {css: {"overflow":"hidden","white-space":"nowrap","text-overflow":"ellipsis"}}
            }
        },
    ]
    return columns;
};

sharesArePeople.search = function () {//查询预约客户列表
    sharesArePeople.table.refresh({query: sharesArePeople.formParams()});
};

sharesArePeople.formParams = function () {// 查询表单提交参数对象 @returns {{}}
    var queryData = {};
    queryData['peopleName'] = $("#peopleName").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    return queryData;
};

sharesArePeople.resetSearch = function () {
    $("#peopleName").val("");
    $("#beginTime").val("");
    $("#endTime").val("");
    sharesArePeople.search()
};

sharesArePeople.inquire = function () {//人数统计 + 表格刷新
    sharesArePeople.search();
};

sharesArePeople.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        sharesArePeople.seItem = selected[0];
        return true;
    }
};

sharesArePeople.openAddsharesArePeople = function () {
    var index = layer.open({
        type: 2,
        title: '添加股份持有者信息',
        area: ['50%', '70%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/sharesArePeople/sharesArePeopleAdd'
    });
    this.layerIndex = index;
};

sharesArePeople.openChangesharesArePeople = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '编辑股份持有者信息',
            area: ['50%', '70%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/sharesArePeople/sharesArePeopleEdit/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};

sharesArePeople.delMgrsharesArePeople = function () {
    if (this.check()) {
        var r = confirm("确认删除？")
        if (r == true) {
            var ajax = new $ax(Feng.ctxPath + "/sharesArePeople/sharesArePeopleDelete/" + this.seItem.id, function (data) {
                Feng.success("删除成功!");
                sharesArePeople.table.refresh();
            }, function (data) {
                alert("没有权限，请联系系统管理员！");
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            });
            ajax.start();
        } else {
        }
    }
};

$(function () {
    var defaultColunms = sharesArePeople.initColumn();
    var table = new BSTable(sharesArePeople.id, "/sharesArePeople/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(sharesArePeople.formParams());
    sharesArePeople.table = table.init();
    checkDate = function () {
        sharesArePeople.inquire();
    };
    $(document).on('click', '#laydate_clear,#laydate_today,#laydate_ok', function () {
        sharesArePeople.inquire();
    });
});
